package com.mmy.dao.visa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.visa.TVisaCollection;

/**
 * 类的介绍：dao层 签证收集信息
 *
 * @author hanxl
 * @date 2020-07-23
 * @version 1.0
 */

public interface TVisaCollectionRepository
		extends JpaRepository<TVisaCollection, Integer>, JpaSpecificationExecutor<TVisaCollection> {
	/* 获取最大值 */
	@Query(value = "select MAX(iCollectionID) from tVisaCollection", nativeQuery = true)
	Object getMaxCollectionID();

	/* 创建 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tVisaCollection(iCollectionID, cOrderID, iStuffID, bSubmit, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);", nativeQuery = true)
	void save(int collectionID);

	@Transactional
	@Modifying
	@Query(value = "UPDATE tVisaCollection SET bSubmit = 1 ,cReviser=:userName,dModifyDate=now() WHERE iCollectionID in(:iCollectionID) ", nativeQuery = true)
	void updateSubmit(@Param("iCollectionID") List<Integer> lstID, @Param("userName") String userName);

}
